package com.ruoyi.kindergarten.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kindergarten.domain.BehaviorMonitor;
import com.ruoyi.kindergarten.service.IBehaviorMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 行为检测与报警模块Controller
 * 
 * @author ruoyi
 * @date 2025-10-26
 */
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@RestController
@RequestMapping("/kindergarten/behaviorMonitor")

public class BehaviorMonitorController extends BaseController
{
    @Autowired
    private IBehaviorMonitorService behaviorMonitorService;

    /**
     * 查询行为检测与报警模块列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BehaviorMonitor behaviorMonitor)
    {
        startPage();
        List<BehaviorMonitor> list = behaviorMonitorService.selectBehaviorMonitorList(behaviorMonitor);
        return getDataTable(list);
    }

    /**
     * 导出行为检测与报警模块列表
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:behaviorMonitor:export')")
    @Log(title = "行为检测与报警模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BehaviorMonitor behaviorMonitor)
    {
        List<BehaviorMonitor> list = behaviorMonitorService.selectBehaviorMonitorList(behaviorMonitor);
        ExcelUtil<BehaviorMonitor> util = new ExcelUtil<BehaviorMonitor>(BehaviorMonitor.class);
        util.exportExcel(response, list, "行为检测与报警模块数据");
    }

    /**
     * 获取行为检测与报警模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:behaviorMonitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(behaviorMonitorService.selectBehaviorMonitorById(id));
    }

    /**
     * 新增行为检测与报警模块
     */
    @PostMapping
    public AjaxResult add(@RequestParam("behaviorName") String  behaviorName,@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        BehaviorMonitor behaviorMonitor = new BehaviorMonitor();
        behaviorMonitor.setBehaviorName(behaviorName);
        return toAjax(behaviorMonitorService.insertBehaviorMonitor(behaviorMonitor,file));
    }

    /**
     * 修改行为检测与报警模块
     */
//    @PreAuthorize("@ss.hasPermi('kindergarten:behaviorMonitor:edit')")
//    @Log(title = "行为检测与报警模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BehaviorMonitor behaviorMonitor)
    {
        return toAjax(behaviorMonitorService.updateBehaviorMonitor(behaviorMonitor));
    }

    /**
     * 删除行为检测与报警模块
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:behaviorMonitor:remove')")
    @Log(title = "行为检测与报警模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(behaviorMonitorService.deleteBehaviorMonitorByIds(ids));
    }
}
